package com.example.dyxeapplication.content.menu.ejaan.belajar;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.example.dyxeapplication.R;
import com.example.dyxeapplication.content.menu.ejaan.belajar.kata.Kata_KX;
import com.example.dyxeapplication.content.menu.ejaan.belajar.kata.perhuruf.Kata_K;
import com.example.dyxeapplication.menu.Menu;
import com.example.dyxeapplication.menu.ejaan.Menu_Ejaan_KX;

public class Ejaan_KX extends Activity implements OnClickListener {
	private Button imgview1, imgview2;
	private MediaPlayer mp;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.menu_ejaan_2);

		Button satu = (Button) findViewById(R.id.satu);
		Button dua = (Button) findViewById(R.id.dua);
		Button tiga = (Button) findViewById(R.id.tiga);

		imgview1 = (Button) findViewById(R.id.b);
		imgview1.setBackgroundResource(R.drawable.kkecil);

		imgview2 = (Button) findViewById(R.id.d);
		imgview2.setBackgroundResource(R.drawable.xkecil);

		imgview1.setOnClickListener(this);
		imgview2.setOnClickListener(this);

		satu.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ejaan_KX.this, Ejaan_KX.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});

		dua.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ejaan_KX.this, Kata_KX.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});

		tiga.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ejaan_KX.this, Kata_K.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (mp != null)
			mp.release();

		if (v.getId() == R.id.b) {
			mp = MediaPlayer.create(this, R.raw.k);

		} else if (v.getId() == R.id.d) {
			mp = MediaPlayer.create(this, R.raw.x);

		}
		mp.seekTo(0);
		mp.start();
	}

	@Override
	public void onPause() {
		super.onPause();
		// Release the MediaPlayer if going into background
		if (mp != null)
			mp.release();
	}

	@Override
	public void onBackPressed() {
		Intent myIntent = new Intent(this, Menu_Ejaan_KX.class);
		myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(myIntent);
	}

	public void home(View v) {
		Intent myIntent = new Intent(this, Menu.class);
		myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(myIntent);
	}
}
